c# enum variable set to nonthing

86

c# enum variable set to nonthing -

An enum is a "value" type in C# (means the the enum is stored as whatever value it is, not as a reference to a place in memory where the value itself is stored). You can't set value types to null (since null is used for reference types only).

That being said you can use the built in Nullable<T> class which wraps value types such that you can set them to null, check if it HasValue and get its actual Value. (Those are both methods on the Nullable<T> objects.

name = "";
Nullable<Color> color = null; //This will work.
There is also a shortcut you can use:

Color? color = null;
That is the same as Nullable<Color>;

Comments

Submit
0 Comments